package com.example.smartplay.controller;

import com.example.smartplay.entity.LoginForm;
import com.example.smartplay.entity.Result;
import com.example.smartplay.service.AdminService;
import com.example.smartplay.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/system")
public class SystemController {
    @Autowired
    private StudentService studentService;
    @Autowired
    private AdminService adminService;
    @Autowired
    private StudentController studentController;
@Autowired
    private AdminController adminController;
    @PostMapping("/login")
    public Result login( @RequestBody LoginForm loginForm){
        Integer userType = loginForm.getUserType();
        if (userType == null) {
            return Result.error("用户类型不能为空");
        }
        switch (userType){
            case 1:
                return studentController.login(loginForm.getUsername(), loginForm.getPassword());
            case 2:
                return adminController.login(loginForm.getUsername(), loginForm.getPassword());
            default:
                return Result.error("无效的用户类型");
        }
    }
}
